<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/pageHead.jsp"%>
<script type="text/javascript">
	function query_datagrid(flag){
		//加载分页控件 datagrid
		$('#datagrid').issdatagrid({
			formid : 'form1',
			title : '<%=MessageResourcesUtils.getMessage(request, "dailyoperation.store.list.title") %>',
			width : 'auto',
			nowrap : true,
			autoRowHeight : false,
			singleSelect : false,
			striped : true,
			url : '${systemctx}/dailyoperation/store/getApproveJson.json',
			sortName : 'modifytime',
			sortOrder : 'desc',
			remoteSort : true,
			idField : 'id',
			pagination : true,
			rownumbers : true,
			showFooter : true,
			queryParams:$('#form1').serializeObject(),
			frozenColumns :[[
				{field:'ck', checkbox:true},
 				{title : '<%=MessageResourcesUtils.getMessage(request,"dailyoperation.store.column.number")%>',field : 'number',sortable : true,align : 'left',formatter: function(value,row,index){
 					return "<a href=\"javascript:void(0);\" onclick=\"view('"+row.id+"')\">"+value+"</a>";
 				}
 				},  
 				{title : '<%=MessageResourcesUtils.getMessage(request,"dailyoperation.store.column.name")%>',field : 'name',sortable : true,align : 'left',width:260,formatter: function(value,row,index){
 					return "<span title='"+value+"'>"+value+"</span>";					
 				}}, 
 				{title : '<%=MessageResourcesUtils.getMessage(request,"dailyoperation.store.column.corporate")%>',field : 'corporate',sortable : true,align : 'left',width:120}
             
             ]],
			columns : [[ 
	              {title : '<%=MessageResourcesUtils.getMessage(request,"dailyoperation.store.column.quality")%>',field : 'quality',sortable : true,align : 'left',width:120}, 
	              {title : '<%=MessageResourcesUtils.getMessage(request,"dailyoperation.store.column.population")%>',field : 'population',sortable : true,align : 'left',width:80}, 
	              {title : '<%=MessageResourcesUtils.getMessage(request,"dailyoperation.store.column.industry")%>',field : 'industry',sortable : true,align : 'left',width:120}, 
	              {title : '<%=MessageResourcesUtils.getMessage(request,"dailyoperation.store.column.businesslicensecode")%>',field : 'businesslicensecode',sortable : true,align : 'left',width:160}, 
	              	{title : '<%=MessageResourcesUtils.getMessage(request,"dailyoperation.store.column.organizationcode")%>',field : 'organizationcode',sortable : true,align : 'left',width:160}, 
	              	{title : '<%=MessageResourcesUtils.getMessage(request,"dailyoperation.store.column.certificatecode")%>',field : 'certificatecode',sortable : true,align : 'left',width:160},
	              {title : '<%=MessageResourcesUtils.getMessage(request,"dailyoperation.store.column.realname")%>',field : 'realname',sortable : true,align : 'left',width:160}, 
	              {title : '<%=MessageResourcesUtils.getMessage(request,"dailyoperation.store.column.state")%>',field : 'state',sortable : true,align : 'center',width:60}
	              <%-- {title : '<%=MessageResourcesUtils.getMessage(request,"dailyoperation.store.column.bussisstatus")%>',field : 'businessstatus',sortable : true,align : 'center',width:70} --%>
	              
            ]],
			onSelectAll:function(rows){
				for(var i = 0; i < rows.length;i ++){
					if (rows[i].state != "<%=MessageResourcesUtils.getMessage(request, "dailyoperation.store.save.refuse")%>" && rows[i].state != "<%=MessageResourcesUtils.getMessage(request, "dailyoperation.store.save.pass")%>") {
	                    $("input[type='checkbox']")[i + 1].checked  = true;
	                }else{
	                	$("input[type='checkbox']")[i + 1].prop("disabled", false);
	                }
				}
			},
			onUnselectAll:function(rows){
				for(var i = 0; i < rows.length;i ++){
					if (rows[i].state != "<%=MessageResourcesUtils.getMessage(request, "dailyoperation.store.save.refuse")%>" && rows[i].state != "<%=MessageResourcesUtils.getMessage(request, "dailyoperation.store.save.pass")%>") {
	                    $("input[type='checkbox']")[i + 1].checked  = false;
	                }else{
	                	$("input[type='checkbox']")[i + 1].prop("disabled", true);
	                }
				}
			},
			onLoadSuccess : function(data) {
				if (data.rows.length > 0) {
	                //循环判断操作为新增的不能选择
	                for (var i = 0; i < data.rows.length; i++) {
	                    //根据operate让某些行不可选
	                    if (data.rows[i].state == "<%=MessageResourcesUtils.getMessage(request, "dailyoperation.store.save.refuse")%>" || data.rows[i].state == "<%=MessageResourcesUtils.getMessage(request, "dailyoperation.store.save.pass")%>") {
	                        $("input[type='checkbox']")[i + 1].disabled = true;
	                    }
	                }
	            }
			}
		});
	}

	$(document).ready(function() {
		$("#state").selectutil({
			optModel : <%=SysConstant.CommonApproveStatus.getMode1JSONString(true, false)%>
		});
		query_datagrid();
		$('#butQuery').click(function() {
			$("#flag").val(1);
			$('#datagrid').datagrid('load',$('#form1').serializeObject());
		});
	});
	
	function approvrInfo(flag,msg){
		var ids = getIds(flag);
		if (ids != '' && ids != undefined) {
			if(confirm(msg)){
				// 显示进度条
				showSending();
				$.ajax({
					type: 'POST',
				    url: '${systemctx}/dailyoperation/store/batchApprove.web?flag='+flag+"&ids="+ids,
				    data: $("#form1").serialize(),
				    dataType: 'json',
				    success: function(data) {
				    	//关闭执行...
						closeSending();
				    	if(data.code == 200){
				    		alert(data.message);
				    		window.location.href="${systemctx}/dailyoperation/store/approveList.web";
				    	}else {
				    		alert(data.message);
				    		return;
				    	}
				    }
				});
			}
		}
	}
	
	function view(id){
		$(this).isswindow({
			noheader : true,
			url :"${systemctx}/dailyoperation/store/storeView.web?id="+id + "&approval=1"
		});
	}
	
	function storeApprovalEdit(id){
		$(this).isswindow({
			noheader : true,
			url :"${systemctx}/dailyoperation/store/storeApprovalEdit.web?id="+id+"&isApprove=1"
		});
	}
	
	function getIds(flag) {
		var ids = "";
		var rows = $('#datagrid').datagrid('getChecked');
		if (rows.length == 0) {
			alert('<%=MessageResourcesUtils.getMessage(request, "dailyoperation.selects.warning")%>');
			return;
		} else {
			if (flag == 1) {
				if (rows.length > 1) {
					messageAlert('<%=MessageResourcesUtils.getMessage(request, "dailyoperation.selects.edit.warning")%>');
					return;
				} else {
					ids = rows[0].id;
					return ids;
				}
			} else {
				for (var i = 0; i < rows.length; i++) {
					ids += rows[i].id + ",";
				}
				if (ids != '') {
					ids = ids.substring(0,ids.length - 1);
				}
				return ids;
			}
		}
	}
</script>

<form name="form1" id="form1">
	<div class="pageMain">
		<div class="pageTitle">
			<%=MessageResourcesUtils.getMessage(request, "systemmanage.storemanagement.title") %>
			<span></span>
			<%=MessageResourcesUtils.getMessage(request, "dailyoperation.store.apply.title") %>
			<span></span>
			<%=MessageResourcesUtils.getMessage(request, "dailyoperation.store.list") %>
		</div>
		<div class="pageBody">
			<div class="form-group">
				<ul>
					<li>
						<i></i>
						<label>
							<%=MessageResourcesUtils.getMessage(request,"dailyoperation.store.column.name") %>
						</label>
						<span>
							<input type="text" name="name" id="name">
							<input type="hidden"  name="flag" id="flag">
						</span>
					</li>
				</ul>
			</div>	
		</div>
		<div class="button-group">
			<input type="button" class="btn btn-default" id="butQuery" value="<%=MessageResourcesUtils.getMessage(request,"common.button.query") %>" />
			<input type="button" class="btn btn-default" onclick="approvrInfo('4','<%=MessageResourcesUtils.getMessage(request,"dailyoperattionstore.approval.ispass") %>')" value="<%=MessageResourcesUtils.getMessage(request,"common.button.pass") %>" />
			<input type="button" class="btn btn-default" onclick="approvrInfo('3','<%=MessageResourcesUtils.getMessage(request,"dailyoperattionstore.approval.isrefused") %>')" value="<%=MessageResourcesUtils.getMessage(request,"common.button.refuse") %>" />
		</div>
		<table width="100%">
			<tbody>
				<tr>
					<td>
						<table id="datagrid"></table>
					</td>
				</tr>
			</tbody>
		</table>
	</div>
</form>

<%-- 引入页面尾 --%>
<%@ include file="/pageFloor.jsp"%>